package com.cruise.game.controller.agent;

import com.cruise.game.common.api.ApiResult;
import com.cruise.game.common.constants.CommonConstants;
import com.cruise.game.controller.BaseController;
import com.cruise.game.model.entity.Agent;
import com.cruise.game.model.param.agent.AgentStatusUpdateParam;
import com.cruise.game.model.param.agent.AgentUpdateParam;
import com.cruise.game.model.vo.agent.AgentProfileVO;
import com.cruise.game.service.agent.AgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 代理(打手)信息控制器
 *
 * @author cruise
 * @date 2025-02-28
 */
@Slf4j
@Api(tags = "代理(打手)信息相关接口")
@RestController
@RequestMapping("/api/agent")
@PreAuthorize("hasRole('ROLE_AGENT')")
public class AgentController extends BaseController {

    @Resource
    private AgentService agentService;

    /**
     * 获取代理个人信息
     */
    @ApiOperation("获取代理个人信息")
    @GetMapping("/profile")
    public ApiResult<AgentProfileVO> getAgentProfile() {
        Long userId = getCurrentUserId();
        return ApiResult.success(agentService.getAgentProfile(userId));
    }

    /**
     * 更新代理信息
     */
    @ApiOperation("更新代理信息")
    @PutMapping("/profile")
    public ApiResult<AgentProfileVO> updateAgentProfile(
            @ApiParam(value = "代理信息", required = true)
            @Validated @RequestBody AgentUpdateParam param) {
        Long userId = getCurrentUserId();
        return ApiResult.success("信息已更新", agentService.updateAgentProfile(userId, param));
    }

    /**
     * 更新代理状态
     */
    @ApiOperation("更新代理状态")
    @PutMapping("/status")
    public ApiResult<String> updateAgentStatus(
            @ApiParam(value = "状态更新", required = true)
            @Validated @RequestBody AgentStatusUpdateParam param) {
        Long userId = getCurrentUserId();
        agentService.updateAgentStatus(userId, param.getStatus());
        return ApiResult.success("状态已更新", param.getStatus());
    }

    /**
     * 获取代理统计信息
     */
    @ApiOperation("获取代理统计信息")
    @GetMapping("/statistics")
    public ApiResult<Object> getAgentStatistics() {
        Long userId = getCurrentUserId();
        return ApiResult.success(agentService.getAgentStatistics(userId));
    }
}